﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Light.Utility.HtmlTable
{
    [Serializable]
    public class RowCollection : CollectionBase
    {
        
        private Table _table;

        
        public RowCollection()
        {
            this._table = null;
        }

        public RowCollection(RowCollection value)
        {
            this._table = null;
            this.AddRange(value);
        }

        public RowCollection(Row[] value)
        {
            this._table = null;
            this.AddRange(value);
        }

        public int Add(Row value)
        {
            value.Table = this.Table;
            return base.List.Add(value);
        }

        public void AddRange(Row[] value)
        {
            for (int i = 0; i < value.Length; i++)
            {
                this.Add(value[i]);
            }
        }

        public void AddRange(RowCollection value)
        {
            for (int i = 0; i < value.Count; i++)
            {
                this.Add(value[i]);
            }
        }

        public bool Contains(Row value)
        {
            return base.List.Contains(value);
        }

        public void CopyTo(Row[] array, int index)
        {
            base.List.CopyTo(array, index);
        }

        public RowEnumerator GetEnumerator()
        {
            return new RowEnumerator(this);
        }

        public int IndexOf(Row value)
        {
            return base.List.IndexOf(value);
        }

        public void Insert(int index, Row value)
        {
            base.List.Insert(index, value);
        }

        public void Remove(Row value)
        {
            base.List.Remove(value);
        }

        
        public Row this[int index]
        {
            get
            {
                return (Row)base.List[index];
            }
            set
            {
                base.List[index] = value;
                ((Row)base.List[index]).Table = this.Table;
            }
        }

        public Table Table
        {
            get
            {
                return this._table;
            }
            set
            {
                this._table = value;
            }
        }

        
        public class RowEnumerator : IEnumerator
        {
            
            private IEnumerator baseEnumerator;
            private IEnumerable temp;

            
            public RowEnumerator(RowCollection mappings)
            {
                this.temp = mappings;
                this.baseEnumerator = this.temp.GetEnumerator();
            }

            public bool MoveNext()
            {
                return this.baseEnumerator.MoveNext();
            }

            public void Reset()
            {
                this.baseEnumerator.Reset();
            }

            bool IEnumerator.MoveNext()
            {
                return this.baseEnumerator.MoveNext();
            }

            void IEnumerator.Reset()
            {
                this.baseEnumerator.Reset();
            }

            
            public Row Current
            {
                get
                {
                    return (Row)this.baseEnumerator.Current;
                }
            }

            object IEnumerator.Current
            {
                get
                {
                    return this.baseEnumerator.Current;
                }
            }
        }
    }




}
